package com.rongke.service.impl;

import java.util.List;

import jodd.util.StringUtil;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.mapper.ReportRecordMapper;
import com.rongke.model.ReportRecord;
import com.rongke.service.ReportRecordService;

import org.springframework.stereotype.Service;

/**
 * @ReportRecordServiceImpl
 * @病历记录报告ServiceImpl
 * @version : Ver 1.0
 */
@Service
public class ReportRecordServiceImpl extends ServiceImpl<ReportRecordMapper, ReportRecord>
                                                                                          implements
                                                                                          ReportRecordService {

    @Override
    public List<ReportRecord> selectByMrId(long mrId) {
        EntityWrapper<ReportRecord> ew = new EntityWrapper<>();
        ew.eq("medical_record_id", mrId);
        ew.orderBy("treatment_date");

        return baseMapper.selectList(ew);
    }

    @Override
    public List<ReportRecord> selectByMrIdAndDate(long mrId, String startDate) {
        EntityWrapper<ReportRecord> ew = new EntityWrapper<>();
        ew.eq("medical_record_id", mrId);
        ew.ge("treatment_date", startDate);
        ew.orderBy("treatment_date", false);

        return baseMapper.selectList(ew);
    }

    @Override
    public List<ReportRecord> selectByMrAndDateRange(long mrId, String startDate, String endDate) {
        EntityWrapper<ReportRecord> ew = new EntityWrapper<>();
        ew.eq("medical_record_id", mrId);

        if (StringUtil.isNotEmpty(startDate)) {
            ew.ge("treatment_date", startDate);
        }

        if (StringUtil.isNotEmpty(endDate)) {
            ew.le("treatment_date", endDate);
        }
        ew.orderBy("treatment_date", false);

        return baseMapper.selectList(ew);
    }
}
